package com.contract.controller;

import com.contract.pojo.output.JsonResult;
import com.contract.service.FileService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;

/**
 * 文件controller
 *
 * @author liw
 * @version 1.0
 * @date 2022/9/13 11:10
 */
@ApiOperation("文件")
@RestController
@RequestMapping("contract/file")
public class BizFileController {

    @Autowired
    private FileService fileService;

    @PostMapping("upload")
    @ApiOperation("上传")
    @PreAuthorize("hasAuthority('file_upload')")
    public JsonResult<Long> upload(@RequestHeader("token") String token, @RequestParam("file") @NotNull MultipartFile file) {
        return fileService.upload(file);
    }

    @GetMapping("download")
    @ApiOperation("下载")
    @PreAuthorize("hasAuthority('file_download')")
    public void download(@RequestHeader("token") String token, @RequestParam("id") Long id) {
        fileService.download(id);
    }

}
